<table class="table table-striped table-hover">
<?php
foreach ($model as $k => $r) {
	//set logo piture
	$url_logo_default = Yii::app()->baseUrl . '/img/thumb_default_offer.png';
	if (!empty($r['url_logo'])) $url_logo = BUtils::GetPictureUrl($r['url_logo']);
	else $url_logo = $url_logo_default;
	
	//tags
	$tags = '';
	$aTags = explode(',', $r['cuisine_type']);
	foreach ($aTags as $tag) {
		$tag = trim($tag);
		if (empty($tag)) continue;
		$tags .= '<span class="label label-light arrowed arrowed-in-right">' . BUtils::T($tag) . '</span>';
	}
	
	//publish button
	$btn_publish = '';
	if ($r['status'] != 1) {
		if (Yii::app()->user->sys_role == 0 or $r['id_admin'] == Yii::app()->user->id) {
			$btn_publish = '<a class="btn btn-mini btn-info ajax-action" href="' . Yii::app()->createUrl('/tools/merchant/publish', array('id'=>$r['id']))
				. '"><i class="icon-rss ajax-ready"></i><i class="icon-refresh icon-spin ajax-loading" style="display:none;"></i> Publish</a>';
		} elseif (empty($r['id_admin']) and $r['status']==0) {
			$btn_publish = '<a class="btn btn-mini btn-info ajax-action" href="' . Yii::app()->createUrl('/tools/merchant/publish', array('id'=>$r['id']))
				. '"><i class="icon-rss ajax-ready"></i><i class="icon-refresh icon-spin ajax-loading" style="display:none;"></i> Publish</a>';
		}
	}
	
	//has offer
	$offers_span = '';
	if ($r['offers'] > 0) {
		$offers_span = '<span class="badge badge-yellow">' . $r['offers'] . ' offer(s)</span>';
	}
?>
<tr class="hover-action">
	<td class="center" style="width:70px;">
		<a href="<?php echo Yii::app()->createUrl('/tools/merchant/view', array('id'=>$r['id'])) ?>">
			<img class="img-polaroid" style="width:64px;" src="<?php echo $url_logo; ?>" alt="" onError="this.onerror=null;this.src='<?php echo $url_logo_default; ?>';" />
		</a>
	</td>
	<td>
		<a href="<?php echo Yii::app()->createUrl('/tools/merchant/view', array('id'=>$r['id'])) ?>"><?php echo $r['name']; ?></a>
		<br />
		<span class="label label-info arrowed arrowed-in-right"><?php echo BUtils::T($r['category_key']); ?></span>
		<br /><?php echo $tags; ?>
	</td>
	<td style="width:180px;">
		<div><?php echo $r['biz_area']; ?></div>
		<div><?php echo $r['address']; ?></div>
		<div><?php echo $r['postcode']; ?>, <?php echo $r['city']; ?></div>
		<div><?php echo $r['phone']; ?></div>
	</td>
	<td style="width:180px;">
		<a class="btn btn-mini" href="<?php echo Yii::app()->createUrl('/tools/offer/form', array('mid'=>$r['id'])); ?>"><i class="icon-certificate"></i> Create offer</a>
		<div class="space-6"></div>
		<a class="btn btn-mini" href="<?php echo Yii::app()->createUrl('/tools/merchant/form', array('id'=>$r['id'])); ?>"><i class="icon-edit"></i> Edit</a>
		<?php echo $btn_publish; ?>
	</td>
	<td style="width:100px;">
		<span class="badge badge-blue"><?php echo (empty($r['rank'])) ? '' : round($r['rank']); ?></span>
		<span class="badge"><?php echo $r['admin_name']; ?></span>
		<br />
		<?php echo $offers_span; ?>
	</td>
</tr>
<?php } ?>
</table>
<div role="grid" class="dataTables_wrapper">
	<div class="dataTables_paginate paging_bootstrap pagination">
<?php
$this->widget('CLinkPager', array(
	'currentPage' => $pages->getCurrentPage(),
	'itemCount' => $pages->getItemCount(),
	'pageSize' => $pages->getPageSize(),
	'prevPageLabel' => '&lt;',
	'nextPageLabel' => '&gt;',
	'firstPageLabel' => '&lt;&lt;',
	'lastPageLabel' => '&gt;&gt;',
	'maxButtonCount' => 10,
	'header' => '',
	'selectedPageCssClass' => 'active',
	'htmlOptions' => array('class'=>'page-ul'),
));
?>
	</div>
</div>
<script type="text/javascript">
$(function() {
	$('.page-ul a').click(function(){
		$.ajax({
			beforeSend:beforeSend, success:success,
			type:'POST', url:$(this).attr('href'), data:$('#search_form').serialize()
		});
		return false;
	});
	
	$('.ajax-action').click(function(ev){
		ev.preventDefault();
		var _this = $(this);
		$.ajax({type:'POST', url:$(this).attr('href'),
			beforeSend: function() {
				_this.attr('disabled', true);
				_this.children('.ajax-ready').hide();
				_this.children('.ajax-loading').show();
			},
			success: function() {
				_this.children('.ajax-ready').show();
				_this.children('.ajax-loading').hide();
				_this.attr('disabled', false);
				_this.hide();
			},
			error: function() {
				_this.children('.ajax-ready').show();
				_this.children('.ajax-loading').hide();
				_this.attr('disabled', false);
			}
		});
	});
});
</script>